para estado
limpa(3,0,24,80,cor,.f.)
limpa(3,0,23,79,cor,.t.)
declare cabeca[4], estrutura[4]
sele funciona
set order to 2 
go top
cabeca[1] = 'ATIVO'        ; estrutura[1] = fiel(16)
cabeca[2] = 'CODIGO'       ; estrutura[2] = fiel(1) 
cabeca[3] = 'NOME'         ; estrutura[3] = fiel(2)
cabeca[4] = 'FUNCAO'       ; estrutura[4] = fiel(3)
menu(24,0,' Inclui ',2,1)
menu(24,8,'Altera ',1,1)
menu(24,15,'Exclui ',1,1)
menu(24,22,'Relatorio ',1,1)
menu(24,32,'Procura ',1,1)
menu(24,72,'Esc-Sai ',1,3)
dbedit(4,1,22,78,estrutura,'fun100','@X',cabeca,.T.)
retu

function fun100(modo,coluna)
set cursor on
if modo = 0 .or. modo = 3
   retu(1)
endif
telalocal=savescreen(4,1,24,80)
tecla = lastkey()
do case
   case tecla = 5 .and. modo = 1

    mensa(10,'Inicio do arquivo ',2)
    retu(2)

   case tecla = 24 .and. modo = 2

    mensa(10,' Final do arquivo ',2)
    retu(2)

   case tecla = 13 .and. estado = 1

    retu(0)

   case tecla = 27

    retu(0)

   case tecla = 73 .or. tecla = 105

    while .t.
       sele funciona
       sombra(8,6,22,78,'Inclusao')
       mmatricula = space(6)   
       @ 10,8 say 'Funcionario   :' get mmatricula pict '@R 99999-!'
       read
       if empty(mmatricula)
          exit
       endif
       set order to 1
       seek mmatricula
       if .not. eof()
          mensa(10,'Funcionario ja cadastrado',2)
          loop
       endif
       set order to 2
       inicializa()
       @ 11,8  say 'Nome          :' get mnome    pict '@!'
       @ 12,8  say 'Funcao        :' get mfuncao  pict '@!'
       @ 13,8  say 'Admissao      :' get madmissao
       @ 14,8  say 'Ativo         :' get mativo   pict '!' valid mativo $ 'AI'
       @ 15,8  say 'Sexo          :' get msexo    pict '!' valid msexo $ 'MF'
       read
       if msexo = 'M'
          @ 16,8  say 'Calca         :' get mcalca   pict '99'
          @ 17,8  say 'Camisa        :' get mcamisa  pict '99'
          @ 18,8  say 'Sapato        :' get msapato  pict '99'
          @ 19,8  say 'Coturno       :' get mcoturno pict '99'
          @ 16,40 say 'Colete        :' get mcolete  pict '99'
          @ 17,40 say 'Jaleco        :' get mjaleco  pict '99'
          @ 18,40 say 'Jaqueta       :' get mjaqueta pict '99'
       else
          @ 16,8  say 'Calca         :' get mcalca   pict '99'
          @ 17,8  say 'Camisa        :' get mcamisa  pict '99'
          @ 18,8  say 'Sapato        :' get msapato  pict '99'
          @ 16,40 say 'Tenis         :' get mtenis   pict '99'
          @ 17,40 say 'Saia          :' get msaia    pict '99'
          @ 18,40 say 'Blazer        :' get mblazer  pict '99'
       endif
       read
       if confirma(18,60,' 1 - Confirma',' 2 - Cancela ')
          appe blank
          if inclusao()
             grava()
             unlock
          endif
       endif
    enddo
    retu(2)

   case tecla = 65 .or. tecla = 97

     sele funciona
     mmatricula = matricula
     sombra(8,6,22,77,'Alteracao')
     @ 10,8 say 'Funcionario   : ' + matricula
     inicializa()
     @ 11,8  say 'Nome          :' get mnome    pict '@!'
     @ 12,8  say 'Funcao        :' get mfuncao  pict '@!'
     @ 13,8  say 'Admissao      :' get madmissao
     @ 14,8  say 'Ativo         :' get mativo   pict '!' valid mativo $ 'AI'
     @ 15,8  say 'Sexo          :' get msexo    pict '!' valid msexo $ 'MF'
     read
     if msexo = 'M'
        @ 16,8  say 'Calca         :' get mcalca   pict '99'
        @ 17,8  say 'Camisa        :' get mcamisa  pict '99'
        @ 18,8  say 'Sapato        :' get msapato  pict '99'
        @ 19,8  say 'Coturno       :' get mcoturno pict '99'
        @ 16,40 say 'Colete        :' get mcolete  pict '99'
        @ 17,40 say 'Jaleco        :' get mjaleco  pict '99'
        @ 18,40 say 'Jaqueta       :' get mjaqueta pict '99'
     else
        @ 16,8  say 'Calca         :' get mcalca   pict '99'
        @ 17,8  say 'Camisa        :' get mcamisa  pict '99'
        @ 18,8  say 'Sapato        :' get msapato  pict '99'
        @ 16,40 say 'Tenis         :' get mtenis   pict '99'
        @ 17,40 say 'Saia          :' get msaia    pict '99'
        @ 18,40 say 'Blazer        :' get mblazer  pict '99'
     endif
     read
     if confirma(18,60,' 1 - Confirma ',' 2 - Cancela  ')
        if alteracao()
           grava()
           unlock
        endif
     endif

   retu(2)

   case tecla = 69 .or. tecla = 101
                 
     sele funciona
     mmatricula = matricula
     madmissao  = ctod('') 
     mfuncao    = space(40)
     sombra(8,6,22,77,'Exclusao')
     @ 10,8 say 'Funcionario   : ' + matricula
     @ 11,8 say 'Nome          :' + nome
     @ 12,8 say 'Funcao        :' get mfuncao  pict '@!'
     @ 13,8 say 'Admissao      :' get madmissao
     read
     if mfuncao # funcao .or. madmissao # admissao
        retu(2)
     endif
     if confirma(18,60,' 1 - Confirma ',' 2 - Cancela  ')
        if alteracao()
           dele
           skip
           unlock
        endif
     endif
   retu(2)

   case tecla = 80 .or. tecla = 112

      sele funciona
      sombra(8,6,22,77,'Procura')
      mnome = space(40)
      @ 10,8 say 'Nome :' get mnome pict '@!'
      read
      set softseek on
      seek mnome
      set softseek off
      retu(2)

   case tecla = 82 .or. tecla = 114

      if .not. impressora()
         retu(2)
      endif
      sele funciona
      sombra(6,4,22,78,'Relatorio')
      mtitulo = .t.
      mpagina = 1
      sele funciona
      go top
      while .not. eof()
       set devi to printer
       if mtitulo
          tit_rela('Funcionarios',mpagina)
          mtitulo = .f.
       endif
       @ prow()+1,0 say trans(matricula,'@R 99999-!') + ' ' + nome + ' ' + ativo + ' ' + sexo
       skip
       if prow() > 54
          eject
          mtitulo = .t.
          mpagina++
       endif
      enddo
      eject
      set devi to screen
      retu(2)

  otherwise

    retu(1)

endcase



 @ 11,8  say 'Nome          :' get mnome    pict '@!'
 @ 12,8  say 'Funcao        :' get mfuncao  pict '@!'
 @ 12,8  say 'Admissao      :' get madmissao
 @ 12,8  say 'Calca         :' get mcalca   pict '99'
 @ 12,8  say 'Camisa        :' get mcamisa  pict '99'
 @ 12,8  say 'Sapato        :' get msapato  pict '99'
 @ 12,8  say 'Japona        :' get mjapona  pict '99'


function codigo()
sele funciona
set order to 1
go top
for x = 1 to 99999
 if x # matricula
    exit
 endif
 skip
next
set order to 2
retu(x)

